home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JCEXPAND.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  2KB  |  76 lines

  1. /*
  2.  * jcexpand.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains image edge-expansion routines.
  9.  * These routines are invoked via the edge_expand method.
  10.  */
  11.  
  12. #include "jinclude.h"
  13.  
  14.  
  15. /*
  16.  * Expand an image so that it is a multiple of the MCU dimensions.
  17.  * This is to be accomplished by duplicating the rightmost column
  18.  * and/or bottommost row of pixels.  The image has not yet been
  19.  * subsampled, so all components have the same dimensions.
  20.  */
  21.  
  22. METHODDEF void
  23. edge_expand (compress_info_ptr cinfo,
  24.          long input_cols, int input_rows,
  25.          long output_cols, int output_rows,
  26.          JSAMPIMAGE image_data)
  27. {
  28.   /* Expand horizontally */
  29.   if (input_cols < output_cols) {
  30.     register JSAMPROW ptr;
  31.     register JSAMPLE pixval;
  32.     register long count;
  33.     register int row;
  34.     short ci;
  35.     long numcols = output_cols - input_cols;
  36.  
  37.     for (ci = 0; ci < cinfo->num_components; ci++) {
  38.       for (row = 0; row < input_rows; row++) {
  39.     ptr = image_data[ci][row] + (input_cols-1);
  40.     pixval = GETJSAMPLE(*ptr++);
  41.     for (count = numcols; count > 0; count--)
  42.       *ptr++ = pixval;
  43.       }
  44.     }
  45.   }
  46.  
  47.   /* Expand vertically */
  48.   /* This happens only once at the bottom of the image, */
  49.   /* so it needn't be super-efficient */
  50.   if (input_rows < output_rows) {
  51.     register int row;
  52.     short ci;
  53.     JSAMPARRAY this_component;
  54.  
  55.     for (ci = 0; ci < cinfo->num_components; ci++) {
  56.       this_component = image_data[ci];
  57.       for (row = input_rows; row < output_rows; row++) {
  58.     jcopy_sample_rows(this_component, input_rows-1, this_component, row,
  59.               1, output_cols);
  60.       }
  61.     }
  62.   }
  63. }
  64.  
  65.  
  66. /*
  67.  * The method selection routine for edge expansion.
  68.  */
  69.  
  70. GLOBAL void
  71. jselexpand (compress_info_ptr cinfo)
  72. {
  73.   /* just one implementation for now */
  74.   cinfo->methods->edge_expand = edge_expand;
  75. }
  76.